define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'guiji/index' + location.search,
                    // add_url: 'guiji/add',
                    edit_url: 'guiji/edit',
                    // del_url: 'guiji/del',
                    // multi_url: 'guiji/multi',
                    table: 'qianbao_sysetm_addr',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        // {field: 'addtime', title: __('Addtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'uname', title: __('Uname')},
                        // {field: 'uid', title: __('Uid')},
                        // {field: 'bp_last_num', title: 'BP余额', operate:'BETWEEN', formatter: function (value,row) {return value * 1}},
                        // {field: 'bp_last_time', title: '查询时间', operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'usdt_last_num', title: 'USDT余额', operate:'BETWEEN', formatter: function (value,row) {return value * 1}},
                        {field: 'usdt_last_time', title: '查询时间', operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'eth_last_num', title: 'ETH余额', operate:'BETWEEN', formatter: function (value,row) {return value * 1}},
                        {field: 'eth_last_time', title: '查询时间', operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'addr', title: __('Addr')},
                        // {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                        {
                            field: 'buttons',
                            // width: "120px",
                            title: '操作',
                            table: table,
                            events: Table.api.events.operate,
                            buttons: [
                                {
                                    name: 'ajax',
                                    text: function (row) {
                                        if(row.usdt_last_num>=Config.guiji_min.USDT){
                                            return '归集USDT';
                                        }else{
                                            return Config.guiji_min.USDT+' 枚起归';
                                        }
                                    },
                                    title: '最小归集数量 '+Config.guiji_min.USDT,
                                    classname: 'btn btn-xs btn-success btn-magic btn-ajax',
                                    icon: 'fa fa-magic',
                                    url: 'guiji/guiji_do?bizhong=usdt',
                                    confirm: '确认归集USDT',
                                    disable: function (row) {
                                        // console.log(config);
                                        if(row.usdt_last_num>=Config.guiji_min.USDT){
                                            return false;
                                        }else{
                                            return true;
                                        }
                                    },
                                    success: function (data, ret) {
                                        Layer.alert(ret.msg + ",返回数据：" + JSON.stringify(data));
                                        $(".btn-refresh").trigger("click");
                                        //如果需要阻止成功提示，则必须使用return false;
                                        //return false;
                                    },
                                    error: function (data, ret) {
                                        // console.log(data, ret);
                                        console.log(ret);
                                        Layer.alert(ret.msg);
                                        return false;
                                    }
                                }
                                // {
                                //     name: 'detail',
                                //     text: __('弹出窗口打开'),
                                //     title: __('弹出窗口打开'),
                                //     classname: 'btn btn-xs btn-primary btn-dialog',
                                //     icon: 'fa fa-list',
                                //     url: 'example/bootstraptable/detail',
                                //     callback: function (data) {
                                //         Layer.alert("接收到回传数据：" + JSON.stringify(data), {title: "回传数据"});
                                //     },
                                //     visible: function (row) {
                                //         //返回true时按钮显示,返回false隐藏
                                //         return true;
                                //     }
                                // },
                                // {
                                //     name: 'addtabs',
                                //     text: __('新选项卡中打开'),
                                //     title: __('新选项卡中打开'),
                                //     classname: 'btn btn-xs btn-warning btn-addtabs',
                                //     icon: 'fa fa-folder-o',
                                //     url: 'example/bootstraptable/detail'
                                // }
                            ],
                            formatter: Table.api.formatter.buttons
                        }
                        
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});